import java.util.ArrayList;
import java.util.Collections;

/**
 * @ClassName CollectionsDemo03
 * @Description TODO
 * @Author Li
 * @Date 2022/8/5 9:18
 * @ModifyDate 2022/8/5 9:18
 * @Version 1.0
 */
public class CollectionsDemo03 {
    public static void main(String[] args) {
        ArrayList<Person> list = new ArrayList<>();
        list.add(new Person("张三", 18));
        list.add(new Person("李四", 19));
        list.add(new Person("王二", 17));
        list.add(new Person("麻子", 20));

        // 按年龄进行升序排序
        Collections.sort(list); // 要求该集合中元素类型类：必须实现比较器Comparable接口

        // 增强for输出集合
        for (Person person : list) {
            System.out.println(person);
        }
    }
}
